package com.adcc.monitoragent.bean;

import java.io.Serializable;
import java.util.List;
/**
 * 服务状态信息 
 * ip+端口+服务名 唯一确定一个服务
 * @author charlie
 *
 */
public class ServiceBean extends BaseBean {
	private static final long serialVersionUID = 1L;
	/**
	 * 固定窜
	 */
	private  String fixType = "service";
	private String serviceName;//服务名
	private String serviceVersion;//服务版本
	private String port;//端口
	private String mac;//mac地址
	private String type;//服务类型   集群/并发
	private String serviceClusterStatus;//只有主备集群使用    主/备
	private long startTime;//启动时间
	private boolean configCluster;//配置文件统一管理
	private List<ServiceNodeBean> nodes;//集群节点
	private JvmMetricsBean jvm;//jvm信息 
	
	public ServiceBean() {
		super();
	}

	public ServiceBean(String key) {
		super();
		String[] temp = key.split(":");
		if(temp.length == 2) {
			this.ip = temp[0];
			this.port = temp[1];
		}
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getServiceVersion() {
		return serviceVersion;
	}

	public void setServiceVersion(String serviceVersion) {
		this.serviceVersion = serviceVersion;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getMac() {
		return mac;
	}

	public void setMac(String mac) {
		this.mac = mac;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public String getServiceClusterStatus() {
		return serviceClusterStatus;
	}

	public void setServiceClusterStatus(String serviceClusterStatus) {
		this.serviceClusterStatus = serviceClusterStatus;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public boolean isConfigCluster() {
		return configCluster;
	}

	public void setConfigCluster(boolean configCluster) {
		this.configCluster = configCluster;
	}

	public List<ServiceNodeBean> getNodes() {
		return nodes;
	}

	public void setNodes(List<ServiceNodeBean> nodes) {
		this.nodes = nodes;
	}

	public JvmMetricsBean getJvm() {
		return jvm;
	}

	public void setJvm(JvmMetricsBean jvm) {
		this.jvm = jvm;
	}

	/**
	 * 服务节点
	 * @author charlie
	 *
	 */
	public static class ServiceNodeBean implements Serializable {
		private static final long serialVersionUID = 1L;
		private String id;//节点编号
		private String status;//主备集群使用信息   主/备
		
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
		public String getStatus() {
			return status;
		}
		public void setStatus(String status) {
			this.status = status;
		}
		@Override
		public String toString() {
			return "ServiceNodeBean [id=" + id + ", status=" + status + "]";
		}
		
	}

	
	@Override
	public String toString() {
		return "ServiceBean [fixType=" + fixType + ", serviceName="
				+ serviceName + ", serviceVersion=" + serviceVersion
				+ ", port=" + port + ", mac=" + mac + ", type=" + type
				+ ", serviceClusterStatus=" + serviceClusterStatus
				+ ", startTime=" + startTime + ", configCluster="
				+ configCluster + ", nodes=" + nodes + ", jvm=" + jvm + "]";
	}

	public String getFixType() {
		return fixType;
	}
	
	/**
	 * 获取关键字唯一标识
	 * @return
	 */
	public String buildKey() {
		return this.ip  + ":" + this.port;
	}
	/**
	 * 构建组名称
	 * @return
	 */
	public String buildGroupName() {
		String name = "";
		try {
			String[] temp = getServiceName().split("\\.");
			name = temp[temp.length - 1].replace("Proxy", "").
					replaceFirst("Service", "");
		} catch (Exception e) {
		}
		return name;
	}
	/**
	 * 获取展现名称   groupName + "_" + ip
	 */
	public void setShowName() {
		setShowName(buildGroupName());
	}
}
